<script>
	import {
		getAccessToken
	} from './request/getAccessToken.js'
	export default {
		created() {
			this.tokenlistenner()
			// setInterval(()=>{
			// 	this.tokenlistenner()
			// },2000)
			this.getAccessToken()
		},
		methods: {
			async tokenlistenner() {
				const token = uni.getStorageSync('token')
				if (token) {
					const res = await uni.$http.post('/user/loginUser')
					// console.log(res)
					if (res.statusCode == 200) {
						uni.setStorageSync('token', res.data.data.token)
						this.$store.commit('initUserInfo', res.data.data)
					}
					if (res.statusCode == 804) {
						uni.removeStorageSync('token')
						uni.showModal({
							title: '已在其他设备登录',
							content: '点击确定将返回登录页面',
							showCancel: false,
							success: function(res) {
								if (res.confirm) {
									uni.navigateTo({
										url: '/pages/login/login'
									})
								}
							}
						});

					}
				}
			},
			async getAccessToken() {
				const {
					data: {
						data: {
							accessToken
						}
					}
				} = await getAccessToken()
				// console.log(accessToken)
				this.$store.commit('saveAccessToken', accessToken)
			}
		}
	}
</script>

<style lang="scss">
	@import "@/uni_modules/uview-ui/index.scss";
	/*每个页面公共css */
	// @import '@/uni_modules/uni-scss/index.scss';
	// /* #ifndef APP-NVUE */
	// @import '@/static/customicons.css';
	// // 设置整个项目的背景色
	// page {
	// 	background-color: #f5f5f5;
	// }
	// /* #endif */
	page {
		background-color: #f5f5f5;
	}
	//#ifdef H5 || MP-WEIXIN
	// text, view, .navigator, .uni-link, .input, .uni-input-placeholder, .input-placeholder, .uni-input-input {
	// 	font-family: KaiTi;
	// }
	//#endif
	
	//#ifdef APP-PLUS
	// @font-face {
	
	// font-family: ele;
	
	// src: url('~@/static/font/ele.TTF');
	
	// }
	// text, view, .navigator, .uni-link, .input, .uni-input-placeholder, .input-placeholder, .uni-input-input {
	// 	font-family: ele;
	// }
	//#endif
</style>
